home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 5 / Amiga Tools 5.iso / tools / developer-tools / c-tools / c_examples / picturedt / picturedt_example.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-06-16  |  4.7 KB  |  155 lines

  1. //////////////////////////////////////////////////////////////////////////////
  2. // PictureDT Example
  3. // 6.16.96 Deryk Robosson
  4. // The PictureDT supports more than just loading and remaping of pictures,
  5. // it also supports all of the DataType Class members such as copying to
  6. // clipboard, saving, printing etc..
  7.  
  8. //////////////////////////////////////////////////////////////////////////////
  9. // Includes
  10. #include "aframe:include/amigaapp.hpp"
  11. #include "aframe:include/window.hpp"
  12. #include "aframe:include/rect.hpp"
  13. #include "aframe:include/button.hpp"
  14. #include "aframe:include/reqtools.hpp"
  15. #include "aframe:include/picturedt.hpp"
  16.  
  17. #include <workbench/startup.h>
  18. #include <workbench/workbench.h>
  19.  
  20. #include <utility/tagitem.h>
  21. #include <proto/utility.h>
  22. #include <clib/utility_protos.h>
  23. #include <pragmas/utility_pragmas.h>
  24.  
  25. //////////////////////////////////////////////////////////////////////////////
  26. // DisplayWindow Class Definition
  27.  
  28. class DisplayWindow : public AFWindow
  29. {
  30.     virtual void OnCloseWindow(LPIntuiMessage imess);
  31.     virtual void OnGadgetUp(LPIntuiMessage imess);
  32.     virtual void OnIDCMPUpdate(LPIntuiMessage imess);
  33.     virtual void DestroyWindow();
  34.     virtual ULONG WindowFlags();
  35.     virtual ULONG WindowIDCMP();
  36. };
  37.  
  38. void DisplayWindow::OnCloseWindow(LPIntuiMessage imess) // time to leave!! ;)
  39. {
  40.     DisplayWindow::DestroyWindow();
  41. }
  42.  
  43. void DisplayWindow::DestroyWindow()
  44. {
  45.     AFWindow::DestroyWindow();
  46.     delete this;
  47. }
  48. ULONG DisplayWindow::WindowFlags()
  49. {
  50.     return (AFWindow::WindowFlags() | WFLG_GIMMEZEROZERO);
  51. }
  52.  
  53. ULONG DisplayWindow::WindowIDCMP()  // We need the IDCMP_IDCMPUPDATE for the TextDT Class
  54. {                                   // if we are to recieve messages for it =)
  55.     return (AFWindow::WindowIDCMP() | IDCMP_IDCMPUPDATE | IDCMP_GADGETDOWN);
  56. }
  57.  
  58. void DisplayWindow::OnGadgetUp(LPIntuiMessage imess)
  59. {
  60.     switch(((struct Gadget*)imess->IAddress)->GadgetID) {
  61.  
  62.     case 100:   // PictureDT Object
  63.         ::RefreshGadgets(m_pWindow->FirstGadget,m_pWindow,(struct Requester*)NULL);
  64.         // Do whatever else here 8)
  65.         break;
  66.     default:
  67.         break;
  68.     }
  69. }
  70.  
  71. void DisplayWindow::OnIDCMPUpdate(LPIntuiMessage imess)
  72. {
  73.     struct TagItem  *attrs;
  74.     struct TagItem  *tag;
  75.  
  76.     attrs=(struct TagItem*)imess->IAddress;
  77.  
  78.     if(tag=FindTagItem(DTA_Busy, attrs)) { // Check for busy status
  79.         if(tag->ti_Data)
  80.             SetWindowPointer(m_pWindow,WA_BusyPointer,TRUE,WA_PointerDelay,TRUE,TAG_DONE);
  81.         else
  82.             SetWindowPointer(m_pWindow,WA_Pointer,NULL,TAG_DONE);
  83.     }
  84.     if(tag=FindTagItem(DTA_Sync,attrs)) // Check for a resync request
  85.         ::RefreshGadgets(m_pWindow->FirstGadget,m_pWindow,(struct Requester*)NULL);
  86. }
  87.  
  88. //////////////////////////////////////////////////////////////////////////////
  89. // ControlWindow Class Definition
  90.  
  91. class ControlWindow : public AFWindow
  92.  
  93. {
  94. public:
  95.     virtual void OnGadgetUp(LPIntuiMessage imess);
  96.  
  97.     AFButton    load;
  98.     AFReqTools  rt;
  99.     AFPictureDT picture;
  100.     DisplayWindow *display;
  101. };
  102.  
  103. //////////////////////////////////////////////////////////////////////////////
  104. // ControlWindow Implementation routines
  105.  
  106. void ControlWindow::OnGadgetUp(LPIntuiMessage imess)
  107. {
  108.   AFRect rect;
  109.  
  110.   switch(((struct Gadget*)imess->IAddress)->GadgetID) {
  111.  
  112.   case 100:     // Load button
  113.     if(!(rt.FileRequest())) {   // Get our filename
  114.         rt.EZRequest("No dir/filename was entered","Ok");
  115.         break;
  116.     }
  117.     if(!(picture.LoadPicture((char*)rt.GetFileName()))) { // Load the picture
  118.         rt.EZRequest("Load File Failed","Ok");
  119.         break;
  120.     }
  121.     display=new DisplayWindow;  // Create a new displaywindow
  122.     picture.m_dtGlobal.dtWindow=display;   // Set the PictureDT window equal to our new window
  123.     rect.SetRect(0,0,640,440);          // Set our new window size and position
  124.     display->Create(m_papp,&rect);      // Create new window
  125.     display->SetWindowTitles((UBYTE*)rt.GetFileName(),(UBYTE*)NULL);    // Set window title same as filename
  126.     rect=picture.FrameObject(display);     // Set size and position of PictureDT
  127.     picture.AddObject(display,&rect, 100); // Add object to our new window
  128.                                            // with the gadid of 998, we could use this as a OnGadgetUp/Down for
  129.                                            // our new displaywindow
  130.     break;
  131.   default:  // Message wasn't really ours :(
  132.     AFWindow::OnGadgetUp(imess);
  133.     break;
  134.   }
  135. }
  136.  
  137. //////////////////////////////////////////////////////////////////////////////
  138. // MAIN
  139.  
  140. void main()
  141. {
  142.     AFAmigaApp theApp;
  143.     ControlWindow win;
  144.     AFRect rect(10,10,410,310);
  145.  
  146.     win.Create(&theApp,&rect,"AFrame PictureDT Example");
  147.  
  148.     rect.SetRect(10,10,50,50);
  149.     win.load.Create("Load",&win,&rect,100);
  150.  
  151.     win.RefreshGadgets();
  152.  
  153.     theApp.RunApp();
  154. }
  155.